<template>
	<view class="my">
			<!-- 头像 -->
			<view class="headPortrait">
				<!-- 头像上半部分 -->
				<view class="headTop">
					<view class="head_left">
						<image :src="touxiang_src"  @click="getUserProfile()"></image>
					</view>
					<p>{{user_name}}</p>
					<span @click="goPages(selfIfo_path)">
						<text>个人信息</text>
						<u-icon name="arrow-right" color="#c7c7c7" size="28rpx"></u-icon>
					</span>
				</view>
				<!-- 头像下半部分 -->
				<view class="headDown">
						<view class="navItem" v-for="item in navArry" @click="goPages(item.path)">
							<image :src="item.imgUrl" mode="" class="navItem_img"></image>
							<view>{{item.name}}</view>
						</view>
				</view>
			</view>
			
			<!-- 客服中心 -->
			<view class="infoCenter">
				<view class="infoImg">
					<image src="../../static/profile_images/kefu.png" mode=""></image>
				</view>
				<text>客服中心</text>
				<view class="seticon">
					<u-icon name="arrow-right" color="#c7c7c7" size="30rpx"></u-icon>
				</view>
			</view>
			<!-- 设置中心 -->
			<view class="setFocus" @click="goPages(setFocus_path)">
				<view class="setImg">
					<image src="../../static/profile_images/shezhi.png" mode=""></image>
				</view>
				<text>
					设置中心
				</text>
				<view class="seticon">
					<u-icon name="arrow-right" color="#c7c7c7" size="30rpx"></u-icon>
				</view>
			</view>
			
	</view>
</template>

<script>
	export default {
		data() {
			return {
				touxiang_src:'',
				user_name:'未登录',
				selfIfo_path:'../../pages2/selfInfo/selfInfo',
				setFocus_path:'../../pages2/setFocus/setFocus',
				navArry:[
					{
						name:"足迹",
						imgUrl:"../../static/profile_images/时钟.png",
						path:'/pages/profile/profile'
					},
					{
						name:"行程",
						imgUrl:"../../static/profile_images/位置.png",
						path:'../../pages2/trip/trip'
					},
					{
						name:"优惠劵",
						imgUrl:"../../static/profile_images/优惠券.png",
						path:'/pages/profile/profile'
					},
					{
						name:"收藏",
						imgUrl:"../../static/profile_images/收藏.png",
						path:'/pages/profile/profile'
					},
				]
			}
		},
		onLoad() {
			uni.$on('pic',(e)=>{
				this.touxiang_src = e.src;
				this.user_name = e.userName;
				console.log(e.src)
			})
		},
		onUnload() {
		    // 移除监听事件  
		        uni.$off('pic');  
		    },
		methods: {
			//获取用户昵称，头像
			getUserProfile(){
				if(this.touxiang_src==''){
					uni.getUserProfile({
						desc:"获取用户名和用户头像",
						lang:"zh_CN",
						success: (res) => {
							this.user_name = res.userInfo.nickName;
							this.touxiang_src = res.userInfo.avatarUrl;
						}
					})
				}
			},
			
			
			//跳转页面
			goPages(url){
				getApp().globalData.headPortrait = this.touxiang_src;
				getApp().globalData.wxName = this.user_name;
				uni.navigateTo({
					url
				})
			},
			
			previewImg(current){
				console.log(current)
				uni.previewImage({
					current:current,
					urls:this.touxiang_srcArry,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my{
		background: rgb(249,249,249);
		
		// 头像部分
		.headPortrait{
			width: 100%;
			background-color: rgb(255,255,255);
			border-radius: 50rpx 50rpx 0rpx 0rpx;
			.headTop{
				display: flex;
				justify-content: space-between;
				border-bottom: 2rpx solid rgb(249,249,249);
				.head_left{
					width: 140rpx;
					height: 140rpx;
					background: #ffaa00;
					border-radius: 99rpx;
					overflow: hidden;
					margin: 80rpx 0rpx 80rpx 60rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				p{
					width: 300rpx;
					font-family: "微软雅黑";
					font-weight: 800;
					font-size: 32rpx;
					margin-top: 130rpx;
					
					
				}
				span{
					line-height: 300rpx;
					display: flex;
					justify-content: space-between;
					font-family: "微软雅黑";
					font-weight: 800;
					color: #c7c7c7;
					font-size: 28rpx;
					margin-right: 30rpx;
					text{
						margin-right: 20rpx;
					}
				}
			}
			
			.headDown{
				display: flex;
				justify-content: space-between;
				border-bottom: 20rpx solid rgb(249,249,249);
				
				.navItem{
					text-align: center;
					width: 33%;
					position: relative;
					.navItem_img{
						width: 100rpx;
						height: 100rpx;
						margin-top: 40rpx;
					}
					view{
						margin-top: 10rpx;
						margin-bottom: 20rpx;
						font-size: 28rpx;
						font-family: "微软雅黑";
					}
					
				}
				.navItem:before{
					content: '';
					position: absolute;
					left: 0;
					top: 70rpx;
					height: 100rpx;
					width: 1rpx;
					background-color: rgb(249, 249, 249);
				}
				
				
			}
		}
		
		// 客服中心
		.infoCenter{
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			background: #FFFFFF;
			display: flex;
			margin-top: 40rpx;
			border-top: 2rpx solid rgb(249,249,249);
			.infoImg{
				width: 60rpx;
				height: 60rpx;
				margin: 20rpx 20rpx 20rpx 40rpx ;
				image{
					width: 100%;
					height: 100%;
				}
			}
			text{
				font-size: 32rpx;
				font-family: "微软雅黑";
				margin-left: 10rpx;			
			    }
			.seticon{
				width: 50rpx;
				height: 30rpx;
				margin-left: 440rpx;
				margin-top: 40rpx;
			}
		}
		
		// 设置中心
		.setFocus{
			display: flex;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			background: #FFFFFF;
			border-top: 2rpx solid rgb(249,249,249);
			border-bottom: 2rpx solid rgb(249,249,249);
			.setImg{
				width: 60rpx;
				height: 60rpx;
				margin: 20rpx 20rpx 20rpx 40rpx ;
				image{
					width: 100%;
					height: 100%;
				}
			}
			text{
				font-size: 32rpx;
				font-family: "微软雅黑";
				margin-left: 10rpx;
			}
			.seticon{
				width: 50rpx;
				height: 30rpx;
				margin-left: 440rpx;
				margin-top: 40rpx;
			}
		}
	}
</style>
